package com.bacon.gmall.order.listener;

import com.bacon.gmall.order.config.OrderDeadLetterMQConfig;
import com.bacon.gmall.order.service.OrderService;
import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.io.IOException;
import java.util.Date;

/**
 * @author： bacon、
 * @version： 1.0
 * @create： 2021-01-11 18:08
 * @description:
 */

@Component
public class OrderConsumer {

    @Autowired
    private OrderService orderService;

    @RabbitListener(queues = OrderDeadLetterMQConfig.QUEUE_ORDER_CANCEL2)
    public void receiverOrderCancelMessage(Long orderId, Channel channel, Message message) throws IOException {
        System.out.println(new Date());
        System.out.println("接收到消息");
        orderService.orderCancel(orderId);
        channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
    }
}
